package com.pan.creational.abstractfactory.factory.child;

import com.pan.creational.abstractfactory.entity.Common;
import com.pan.creational.abstractfactory.factory.AbstractFactory;
import com.pan.creational.abstractfactory.utils.AbstractFactoryUtils;

public class ShapeFactory extends AbstractFactory {

    @Override
    public Common get(String type) {
        String shapeName = AbstractFactoryUtils.INSTANCE.getClassname(type);
        Object shape = null;
        try {
            shape = Class.forName(shapeName).getConstructor().newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return (Common) shape;
    }
}
